<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>寄生式组合继承</title>
</head>
<body>
  <script>
    function object(o) {
      function F() {}
      F.prototype = o;
      return new F();
    }
    
    function inheritPrototype(subType, superType) {
      let prototype = object(superType.prototype);
      prototype.constructor = subType;
      subType.prototype = prototype;
    }

    function SuperType(name) {
      this.name = name;
      this.colors = ["red", "blue", "green"];
    }

    SuperType.prototype.sayName = function() {
      console.log(this.name);
    };

    function SubType(name, age) {
      SuperType.call(this, name);
      this.age = age;
    }

    inheritPrototype(SubType, SuperType);

    SubType.prototype.sayAge = function() {
      console.log(this.age);
    };
  </script>
</body>
</html>